// ProjectName: go-learn-demo
// PackageName: _5_reflect
// Description: float64类型的变量的反射操作
// Author: hy.bai
// Date: 2025-08-13 星期三 19:00

package reflectybxb

import (
	"fmt"
	"reflect"
)

func TestFloatReflect() {

	// 定义一个float类型的变量
	var abc float64 = 3.141592653589793
	fmt.Println("TypeOf-----------------------------------------------------")
	floatType := reflect.TypeOf(abc)
	fmt.Println("TypeOf - Type:", floatType)        // 打印: TypeOf - Type: float64
	fmt.Println("TypeOf - Kind:", floatType.Kind()) // 打印: TypeOf - Kind: float64
	fmt.Println("ValueOf-----------------------------------------------------")
	floatValue := reflect.ValueOf(abc)
	fmt.Println("ValueOf - value:", floatValue)         // ValueOf - value: 3.141592653589793
	fmt.Println("ValueOf - type:", floatValue.Type())   // ValueOf - type: float64
	fmt.Println("ValueOf - Kind:", floatValue.Kind())   // ValueOf - Kind: float64
	fmt.Println("ValueOf - Float:", floatValue.Float()) // ValueOf - Float: 3.141592653589793
	fInter := floatValue.Interface()
	fmt.Println(fInter)                         // 3.141592653589793
	fmt.Printf("floatValue is %5.2e\n", fInter) // floatValue is 3.14e+00
	result, r := fInter.(float64)               // 注意：Go语言中的断言是有两个值
	if !r {
		fmt.Println("转换失败")
		return
	}
	fmt.Println(result) // 3.141592653589793
	fmt.Println("Kind-----------------------------------------------------")
	// Go语言中的自定义类型
	type MyInt int
	var mi MyInt = 10
	miValue := reflect.ValueOf(mi)
	fmt.Println("Type:", miValue.Type()) // Type()返回类型MyInt。即：打印：Type: reflectybxb.MyInt
	fmt.Println("Kind:", miValue.Kind()) // Kind()返回底层的类型int。即：打印：Kind: int
}
